package com.koron.css2.clientCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.UserGroupBean;
import com.koron.css2.clientCenter.mapper.UserGroupMapper;
import com.koron.css2.clientCenter.mapper.UserInfoMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

public class UserGroupDelete implements ServerInterface{

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MessageBean<String> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "删除成功", String.class);
		try {
			UserGroupBean bean = JsonUtils.objectToPojo(req.getData(), UserGroupBean.class);
			
			UserGroupMapper mapper = factory.getMapper(UserGroupMapper.class);
			UserInfoMapper uiMapper = factory.getMapper(UserInfoMapper.class);
			mapper.delete(bean.getUserGroupNo());
			uiMapper.updateUserGroupNoNull(bean.getUserGroupNo());
			return info;
		}catch (Exception e) {
			// TODO: handle exception
			logger.error("用户组删除失败" + e.getMessage(), e);
			return  MessageBean.create(Constant.MESSAGE_INT_FAIL, "删除失败", null);
		}
	}

}
